package com.team.arms.tijian.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.team.arms.common.Result;
import com.team.arms.common.ry.core.domain.AjaxResult;
import com.team.arms.tijian.entity.vo.AllVO;
import com.team.arms.tijian.entity.vo.RecommendVo;
import com.team.arms.tijian.mapper.RecommendedMapper;
import com.team.arms.tijian.mapper.SysHealthExaminationMapper;
import com.team.arms.tijian.service.IRecommendedService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author huazige
 * @Date 2022/6/6 12:57
 * @Version 1.0
 */
@RestController
@RequestMapping("/confirm")
@CrossOrigin
@Api(tags="体检-个人确认模块")
public class PersonConfirmController {
    @Autowired
    RecommendedMapper recommendedMapper;

    @Autowired
    IRecommendedService iRecommendedService;
    @Autowired
    SysHealthExaminationMapper sysHealthExaminationMapper;

    @ApiOperation("获取个人确认页面")
//    @Log(title = "政审信息", businessType = BusinessType.)
    @GetMapping(value = "/get")
    public AjaxResult getreconfirm() {
        String healthExaminStats="待个人确认";
        List<RecommendVo> list = recommendedMapper.select(healthExaminStats);
//

        if (list != null) {
            return AjaxResult.success("查询成功", list);
        } else {
            return AjaxResult.error("查询失败");
        }
    }
    @ApiOperation(value = "个人确认页面-下拉框查找")
    @GetMapping("/found")
    public AjaxResult getreconfirmbyname(@RequestParam(value = "查询的字段") String field , @RequestParam(value = "查询的内容")String content) {
        //也可以直接从redis缓冲中去调用一个foreach循环拿到对应name的数据
        String healthExaminStats="待个人确认";
        List<RecommendVo> list = recommendedMapper.selectbyname(field,content,healthExaminStats);

        if (list.size()>0){
            return AjaxResult.success("姓名查找成功",list);
        }else {
            return    AjaxResult.success("没有找到姓名信息");
        }

    }
    @ApiOperation("获取某个人的详情内容")
    @GetMapping(value = "/getall/{examineId}}")
    public AjaxResult selectall(
            @PathVariable("examineId")String examineId
    ) {

        List<AllVO> list = sysHealthExaminationMapper.select(examineId);
        return AjaxResult.success("查询成功",list) ;

    }

    @ApiOperation("复检/单个+批量删除")
    @DeleteMapping("/examineId")
    public Result deleteInformation(
            @ApiParam("体检编号") @RequestParam("examineId")List<String> deletelist ) {
        int delete =0;

        for ( String id:deletelist
        ) {
            QueryWrapper<entity.SysHealthExamination> wrapper = new QueryWrapper();
            wrapper.eq("examine_id",id);

            delete = sysHealthExaminationMapper.delete(wrapper);


        }
        if (delete>0){
            return Result.success("批量删除成功");
        }
        return Result.error("批量删除失败");
    }
}
